﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using log4net;
using UTSDAL.LINQSQL.Model;

/// <summary>
/// Summary description for TimeUtils
/// </summary>
public class TimeUtils
{
    public TimeUtils()
    {

    }


    private static readonly ILog log = LogManager.GetLogger(typeof(TimeUtils));

    public static String adjustTimeString(String timeString)
    {
        timeString = timeString.Trim();

        if (timeString.Length == 4)
        {
            timeString = "0" + timeString;
        }

        log.Debug("Time String in Utils = " + timeString);

        return timeString;
    }

    public static Boolean isTimeSpanNull(TimeSpan timeSpan)
    {
        return timeSpan.ToString().Equals("00:00:00") || timeSpan.ToString().Equals("00:00");
    }

    public static String convertTimespan(TimeSpan timeSpan)
    {

        DateTime time = DateTime.MinValue.Add(timeSpan);

        return time.ToString("HH:mm");
    }

    /*
     *This method to check whether a timetable event is existing in the database
     *or has been created by a delegated method
     *Example Usage: in Insert/Edit Reservation to check / uncheck reservation checkbox for event
     * 
     */
    public static Boolean isTimetableEventNew(TimetableEvent timetableEvent)
    {
        
        return isTimeSpanNull(timetableEvent.StartTime) || isTimeSpanNull(timetableEvent.EndTime);

    }
}